import { LogOut } from '@/api/user'  // 导入用户信息相关接口
import { removeToken } from '@/utils/auth'


const user  = {
  state : {
    name:'',
    roles: [],
  },
  getters : {
    roles: state => state.roles,
    name: state => state.name,
  },
  mutations: {
    SET_ROLES: (state, roles) => {
        state.roles = roles
    },
  
    SET_NAME: (state, name) => {
      state.name = name
    },
  },
  actions:{
      //登出
      LogOut({ commit, reqData }) {
        return new Promise((resolve, reject) => {
          LogOut(reqData).then(response => {
            commit('SET_ROLES', [])
            removeToken()
            resolve()
          })
        })
      }
      
  }
}

export default user;